<template>
  <view class="page">
    <div class="header">
      <div class="flex">
        <div>当前可用次数(次)</div>
      </div>
      <div class="flex money">
        <div class="count">{{ designerUser?.points }}</div>
        <div class="flex btns">
          <div class="tixian chongzhi" @click="bindChongZhi()">充值</div>
        </div>
      </div>
      <div class="tixian-list">
        <div class="tx-item">
          <div class="tx-title">累计使用次数</div>
          <div class="tx-money">{{ designerUser.usePoints || 0 }}次</div>
          <image class="right-icon" src="https://cos.aitshirt.cn/app-icon/%E8%B7%AF%E5%BE%84%20224%402x.png" alt=""></image>
        </div>
        <div class="tx-item">
          <div class="tx-title">有效期</div>
          <div class="tx-money">永久</div>
          <image class="right-icon" src="https://cos.aitshirt.cn/app-icon/%E8%B7%AF%E5%BE%84%20224%402x.png" alt=""></image>
        </div>
      </div>
    </div>
    <div class="good-content" >
      <div class="good-ul pay" style="height: calc(100vh - 350rpx)">
        <ScrollList :finished="isFinished" :loading="isLoading" :show-empty="isFinished && !list?.length" style="height: calc(100vh - 100rpx); width: calc(100vw - 32rpx)" @load="load" @refresh="reset">
          <MmonePayItem v-for="item in list" :key="item.id" :item="item"/>
        </ScrollList>
      </div>
    </div>
  </view>
</template>

<script setup lang="ts">
import MmonePayItem from '@/components/MmonePayItem.vue';
import { shallowRef } from 'vue';
import { getDesignUser, getObtainPersonalTransactionRecords } from '@/api/designUser';
import { onShow } from '@dcloudio/uni-app';
import { usePagination } from '@/hooks/usePagination';
import ScrollList from '@/components/scroll-list/scroll-list.vue';
import { useRouter } from "uni-mini-router"
const router = useRouter();
const { list, isLoading, load, reset, isFinished } = usePagination(queryProducts);
function queryProducts(page = 1) {
  const data = {
    page: page,
    type: 4,
  };
  return getObtainPersonalTransactionRecords(data).then(res => {
    return {
      data: res.data.list,
      total: res.total,
    };
  });
}

const designerUser = shallowRef<any>({});
function queryDesignUser() {
  getDesignUser().then((res) => {
    designerUser.value = res.data;
  });
}
onShow(() => {
  queryDesignUser();
  reset();
});

const bindChongZhi = () => {
  router.push({
    path: '/pages/wallet/recharge/recharge',
  })
};
</script>

<style scoped lang="scss">
.flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.page {
  background: #f3f7f8;
  padding: 16rpx;
}
.header {
  display: flex;
  flex-direction: column;
  //width: 100%;
  //height: 250rpx;
  background: #ffffff;
  box-shadow: 0rpx 2rpx 4rpx 2rpx rgba(0, 0, 0, 0.08);
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  padding: 32rpx 16rpx;
  .flex {
    font-weight: 400;
    font-size: 28rpx;
    color: #222222;
    &.money {
      margin: 16rpx 0;
    }
  }
  .count {
    height: 90rpx;
    font-weight: bold;
    font-size: 64rpx;
    color: #f25a27;
    line-height: 90rpx;
  }

  .count-no {
    height: 32rpx;
    font-weight: bold;
    font-size: 24rpx;
    color: #222222;
    line-height: 32rpx;
  }
  .btns {
    gap: 16rpx;
    .tixian {
      width: 120rpx;
      height: 48rpx;
      background: #f3f7f8;
      border-radius: 32rpx 32rpx 32rpx 32rpx;
      font-weight: bold;
      font-size: 28rpx;
      color: #222222;
      line-height: 48rpx;
      text-align: center;
      &.chongzhi {
        background: #f25a27;
        color: #ffffff;
      }
    }
  }

  .tixian-list {
    position: relative;
    display: flex;
    align-items: center;
    height: 66rpx;
    gap: 64rpx;
    &:after {
      position: absolute;
      left: 50%;
      content: '';
      width: 0rpx;
      height: 32rpx;
      border: 1rpx solid #e4e4e4;
      transform: translateX(-50%);
    }
    .tx-item {
      width: 50%;
      display: flex;
      align-items: center;
      font-weight: 400;
      font-size: 24rpx;
      color: #222222;
      line-height: 32rpx;
      .tx-title {
      }
      .tx-money {
        font-weight: bold;
        margin: 0 16rpx;
      }
      .right-icon {
        width: 12rpx;
        height: 20rpx;
        margin-left: auto;
      }
    }
  }
}

.good-content {
  background: #ffffff;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  margin: 16rpx 0;
  .pay {
    .pay-li {
      height: 120rpx;
      .image-detail {
        .image-content {
          image {
            width: 72rpx;
            height: 72rpx;
          }
        }
      }
    }
  }
}
</style>
